<?php
/**
 * 上楼设置
 * edition ：v1
 * create time：2021-06-08
 * author: acker
 */
namespace App\Admin\Controllers\System;



use App\Http\Controllers\Controller;
use App\Models\DataDictionaryModel;
use App\Models\yb\SettingModel;
use Encore\Admin\Form;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Grid;
use Encore\Admin\Show;


class GoupstairsController extends Controller
{
    use ModelForm;

    protected $header = '其他设置';


    /**
     * 新增
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->header);
            $content->description('创建');
            $content->body($this->form());

        });
    }

    /**
     * 编辑
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header($this->header);
            $content->description('编辑');
            $content->body($this->form()->edit($id));

        });
    }


    /**
     * @return mixed
     */
    public function form(){

        $form = new Form(new SettingModel());

        $form->radio('is_todoor_fee', '步梯是否收费')
            ->options(DataDictionaryModel::Whether)->when(1, function (Form $form) {
                $form->number('todoor_fee_floor', '收费楼层')->help('从第几层开始收费');

                $form->currency('todoor_amount', '收费金额')->symbol('￥');
        });

        $form->radio('is_delivery_fee', '满额是否减配送费')
            ->options(DataDictionaryModel::Whether)->when(1, function (Form $form) {
                $form->currency('delivery_fee', '满额多少额')->symbol('￥');
            });

        $form->text('customer_phone', '客服电话');

        $form->tools(function (Form\Tools $tools) {
            $tools->disableView();
            $tools->disableDelete();
            $tools->disableList();
        });

        $form->footer(function ($footer) {
            // 去掉`查看`checkbox
            $footer->disableViewCheck();
        });

        $form->saved(function (Form $form) {
            return redirect('/admin/system/goupstairs/setting/1/edit');
        });

        return $form;
    }


}
